<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Core.DAL.tSite_Photos_Image>>" %>

<asp:Content ID="cHead" ContentPlaceHolderID="cphHead" runat="server">
    <% this.Page.Title = (string)ViewData["PageTitle"]; %>
</asp:Content>

<asp:Content ID="cMeta" ContentPlaceHolderID="cphMeta" runat="server">
    <meta name="title" content="<%= ViewData["MetaTitle"] %>" />
    <link rel="image_src" href="<%= ViewData["MetaThumbnail"]  %>" />
</asp:Content>

<asp:Content ID="cJScripts" ContentPlaceHolderID="cphJScripts" runat="server">
    <% if (UsersRepository.GetUserType((string)ViewData["SystemName"]) != UserType.User){ %>
    <script type="text/javascript">
        $(document).ready(function () {
            $(".imagethumb").mouseenter(function () {
                $(this).find(".adminTools").show();
            }).mouseleave(function () {
                $(this).find(".adminTools").hide();
            });

            $(".deleteItem").colorbox({ width: "400px", height: "200px", iframe: true, title: "Supprimer une photo" });

            $(".rightRotationItem, .leftRotationItem").click(function(){
                $(this).parent('div').parent('div').find('img:last').attr('src', $(this).attr('href') + '?ts=' + Math.floor(Math.random() * 110));
                return false;
            });

            $(".defaultItem").click(function(){
                 var url = $(this).attr('href');
                 var item = $(this);
                 var $tools = $(this).parent('div');
                 $.ajax({
                    type: "POST",
                    url: url,
                    data : "AID=" + item.attr("rel"),
                    success: function() {
                        $tools.hide();
                        $tools.parent('div').effect("pulsate", null, 500);
                    }
                });
                return false;
            });
        });

        function DeleteAlbum(AID){
            $.ajax({
                type: "POST",
                url: "/<%= (string)ViewData["SystemName"] %>/Album/Delete",
                data: 'ID=' + AID,
                success: function(returnMessage) {
                    $("." + AID).hide("fast");
                }
            });
        }

        function DeletePicture(IID) {
            $.ajax({
                type: "POST",
                url: "/<%= (string)ViewData["SystemName"] %>/Photo/Delete",
                data: 'ID=' + IID,
                success: function(returnMessage) {
                    $("." + IID).hide("fast");
                }
            });
        }
    </script>
    <% } %>
    <script type="text/javascript">
        $("body, html").keydown(function (e) {
            if (e.keyCode == 39) { // Right
                if ($("#paginator a.next").length != 0) {
                    location.href = $("#paginator a.next").attr("href");
                }
            }
            else if (e.keyCode == 37) { // Left
                if ($("#paginator a.prev").length != 0) {
                    location.href = $("#paginator a.prev").attr("href");
                }
            }
        });
    </script>
</asp:Content>

<asp:Content ID="cMainContent" ContentPlaceHolderID="cphMainContent" runat="server">

    <div id="album">
        <table border="0" cellpadding="10" cellspacing="1" summary="">
<% 
            int i = 0;
            int j = 1;
            bool isAdminUser = (UsersRepository.GetUserType((string)ViewData["SystemName"]) != UserType.User);
            foreach (var item in Model) { 
                
            if (i == 0){
%>
            <tr>
<% } %>
        
            <td align="center">
			    <div class="imagethumb<%= (j % 2 == 1) ? " rotation" : string.Empty %> <%= item.ID %>">
                    <% if (isAdminUser) { %>
                    <div class="adminTools">
                        <%= Html.ActionLinkImage("Supprimer", "/Design/Images/SiteImages/spacer.gif", "Delete", new { controller = "Photo", systemName = (string)ViewData["SystemName"], ID = item.ID }, new { @class = "deleteItem" })%>
                        <%= Html.ActionLinkImage("Rotation vers la droit", "/Design/Images/SiteImages/spacer.gif", "RightRotationImage", new { controller = "Album", systemName = (string)ViewData["SystemName"], ID = item.ID, Title = ((string)ViewData["TitleAlbum"]).ParseUrl() }, new { @class = "rightRotationItem" })%>
                        <%= Html.ActionLinkImage("Rotation vers la gauche", "/Design/Images/SiteImages/spacer.gif", "LeftRotationImage", new { controller = "Album", systemName = (string)ViewData["SystemName"], ID = item.ID, Title = ((string)ViewData["TitleAlbum"]).ParseUrl() }, new { @class = "leftRotationItem" })%>
                        <%= Html.ActionLinkImage("Image par defaut", "/Design/Images/SiteImages/spacer.gif", "DefaultPicture", new { controller = "Album", systemName = (string)ViewData["SystemName"], ID = item.ID, Title = ((string)ViewData["TitleAlbum"]).ParseUrl() }, new { @class = "defaultItem", rel = (int)ViewData["AlbumID"] })%>
                    </div>
                    <% } %>
			        <%= Html.ActionLinkImage(item.AlbumName, Html.ImageResizedUrl("Album", "ImageResize", item.AlbumName, item.ID), "Index", new { controller = "Photo", systemName = (string)ViewData["SystemName"], page = (int)ViewData["SkipItems"] + j, ID = (int)ViewData["AlbumID"], Title = ((string)ViewData["TitleAlbum"]).ParseUrl() }, new { title = (string)ViewData["TitleAlbum"] })%>
			    </div>
		    </td>
<% 
            i++;
            j++;
            if (i == 3 || i == (int)ViewData["TotalItems"])
            {
                i = 0;
%>
            </tr>
<% }}  %>
        </table>
    </div> 

    <hr />
    <%= Html.PagerLinks((int)ViewData["Page"], (int)ViewData["TotalPages"], "Index", new { controller = "Album", systemName = (string)ViewData["SystemName"], Title = ((string)ViewData["TitleAlbum"]).ParseUrl(), ID = (int)ViewData["AlbumID"] })%>

</asp:Content>

<asp:Content ID="cAdminMenu" runat="server" ContentPlaceHolderID="cphAdminMenu">
    <% if (ViewData["UserType"] != null && ((UserType)ViewData["UserType"] == UserType.Moderator || (UserType)ViewData["UserType"] == UserType.Administrator)) {  %>
    <ul id="adminMenu">
        <li class="edit"><%= Html.ActionLink(ScoutNET.Resources.Galerie_Index_EditLink, "Edit", new { controller = "Galerie", systemName = (string)ViewData["SystemName"], ID = (int)ViewData["AlbumID"] })%></li>
        <li class="create"><%= Html.ActionLink(ScoutNET.Resources.Galerie_Index_AddPictureLink, "Edit", new { controller = "Album", systemName = (string)ViewData["SystemName"], ID = (int)ViewData["AlbumID"] })%></li>
        <li class="create"><%= Html.ActionLink(ScoutNET.Resources.Galerie_Index_CreateLink, "Create", new { controller = "Galerie", systemName = (string)ViewData["SystemName"] })%></li>
    </ul>
    <% } %>
</asp:Content>

